module Singly
  class Error < StandardError
    class << self
      # Racist closure for raising errors
      # Usage:
      #  unhappy = true
      #  Singly.y_u_no?("happy") { unhappy }
      # => Singly::Error: y u no happy???
      def y_u_no?(msg)
        raise Error.new("y u no #{msg}???") if yield
      end
    end
  end
  class ApiError < Error
    def initialize(opts)
      super(opts.inspect)
    end
  end
  class TimeoutError < ApiError
    def initialize(opts)
      super(opts)
    end
  end
end